echo Applying ../deploy/deployment.yaml
kubectl apply -f ../deploy/deployment.yaml || kubectl create -f ../deploy/deployment.yaml || exit 1
sched_pod_to_delete=$(kubectl get pods --namespace=kube-system | grep scheduler-framework-sample | awk -F ' ' '{print $1}') || exit 1


if [ "${sched_pod_to_delete}" != "" ];then
    for i in ${sched_pod_to_delete};
    do
        echo To delete old scheduler pod: $i
        kubectl delete pod $i -n kube-system
        echo Old scheduler pod deleted: $i
    done
    
else
    echo No old scheduler pods to delete!
fi

nginx_pod_to_delete=$(kubectl get pods | grep test-nginx | awk -F ' ' '{print $1}') || exit 1

if [ "${nginx_pod_to_delete}" != "" ];then
    for i in ${nginx_pod_to_delete};
    do
        echo To delete old nginx pod: $i
        kubectl delete pod $i
        echo Old nginx pod deleted: $i
    done
else
    echo No old nginx pods to delete!
fi

echo Applying ../deploy/nginx.yaml

kubectl apply -f ../deploy/nginx.yaml || kubectl create -f ../deploy/nginx.yaml || exit 1

